<?php

/**
 * 获取有赞所有商品分类
 *
 **/

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Doraemon\tools\Youzan;
use hhz\constant\redis\redisKeys;
use Hhz\Redis\newCache;

$allCategory = [];
$page = 1;
$pageSize = 20;
$res = Youzan::categoryQuery($page, $pageSize);
if ($res) {
    $allCategory = array_merge($allCategory, $res['categorys']);
    $page = 2;
    $count = $res['paginator']['total_count'];
    var_dump('查询到总数:' . $count . '条');
    do {
        $res = Youzan::categoryQuery($page, $pageSize);
        $categorys = $res['categorys'] ?? [];
        var_dump('查询第:' . $page . '页数据' . count($categorys) . '条');
        $allCategory = array_merge($allCategory, $categorys);
        $page++;
    } while ($categorys);
    var_dump($allCategory);
}

if($allCategory){
    $redis = new newCache(redisKeys::KEY_B_CACHE_SUPER_SUBSIDY_DAY_SPU_CATEGORY);
    $redis->setCache($allCategory);
}



